home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
PROG_TOO
/
C013.ZIP
/
HDR.C
< prev
next >
Wrap
Text File
|
1990-01-19
|
3KB
|
113 lines
/********************************************************************
* C Users Group (U.K) C Source Code Library File CUGLIB.013 *
* Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd. *
* Edgbaston, Birmingham B15 2QN ENGLAND *
********************************************************************
* File name: hdr.c
* Program name:hdr
* Source of file: Ron Wellstead
* Purpose: An MS-DOS copy of the UNIX utility of the same name.
* Changes: <who what when & why major changes have been made>
********************************************************************/
/*
*
* @(#) hdr.c 1.2 87/07/27
*
* UNIX style hdr utility for dos
*
* copyright (c) 1987 Ron Wellsted.
* This software is provided on the understanding that it is
* NOT to be used for commercial gain. It may be freely distributed
* in source or object form among amateur and hobby computer users ONLY!
*
* displays the .exe header of files on stdout
* usage: hdr files....
* written for Microsoft C, link with setargv.obj to expand wildcards
*/
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
char what[] = "@(#)hdr.c VR 1.0.0 15 Jul 1987";
struct
{
unsigned magic, /* magic no.(0x5a4d) */
bytes, /* bytes in last page */
pages, /* no. of pages in file */
nreloc, /* no. of reloc entries */
hdrsz, /* size of header (para)*/
minalloc, /* min alloc size (para)*/
maxalloc, /* max alloc size (para)*/
initss, /* initial SS value */
initsp, /* initial SP value */
chcksum, /* -ve checksum of file */
initip, /* initial IP value */
initcs, /* initial CS value */
rlocoff, /* byte offs to reloc */
ovrlay; /* overlay no. */
} exe_hdr;
main (argc,argv)
int argc;
char *argv[];
{
int i,j;
if (argc<2)
{
fprintf(stderr,"Usage: hdr file [... fileN]\n");
exit(1);
}
for (i=1;i<argc;i++)
{
if ((j=hdr(argv[i]))>0)
fprintf(stderr,"hdr: %s: not an .exe format file\n",
argv[i]);
else if (j<0)
{
fprintf(stderr,"hdr: ");
perror(argv[i]);
}
}
exit(0);
}
hdr(ptr)
char *ptr;
{
int fh, i;
unsigned long l;
if (( fh = open(ptr, O_RDONLY|O_BINARY)) < 0) return fh;
lseek(fh, 0L, 0);
i = sizeof(exe_hdr);
if (i != read(fh, (char *)(&exe_hdr), i)) return 1;
else if (exe_hdr.magic != 0x5a4d) return 1;
else
{
printf("file %s :\n",ptr);
printf("magic number = 0x%x\n", exe_hdr.magic);
l = (long)(exe_hdr.pages - 1) * 512L;
l += (long)(exe_hdr.bytes);
printf("file length = %6ld\n", l);
printf("relocation size = %6d\n", exe_hdr.nreloc);
printf("header size = %6d\n", exe_hdr.hdrsz * 16);
l = (long)(exe_hdr.minalloc) * 16L;
printf("minimum allocation = %6ld\n", l);
l = (long)(exe_hdr.maxalloc) * 16L;
printf("maximum allocation = %7ld\n", l);
printf("initial SS:SP = %04x:%04x\n", exe_hdr.initss,
exe_hdr.initsp);
printf("initial CS:IP = %04x:%04x\n", exe_hdr.initcs,
exe_hdr.initip);
printf("checksum = 0x%04x\n", exe_hdr.chcksum);
printf("relocation offset = %6d\n", exe_hdr.rlocoff);
printf("overlay number = %6d\n\n", exe_hdr.ovrlay);
}
return close(fh);
}